package com.tougutips.config;

import com.tougutips.common.redis.service.RedisService;
import com.tougutips.common.utils.StringUtil;
import com.tougutips.entity.Goods;
import com.tougutips.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 项目启动时对商品信息进行缓存操作,有问题,数据一致性?
 */
@Component
public class GoodsInitCache implements ApplicationRunner {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private RedisService redisService;

    @Override
    public void run(ApplicationArguments args){
        List<Goods> list = goodsService.list();
        if (list.size() > 0) {
            redisService.setCacheList("goodsList", list);
        }
    }
}
